import java.awt.Color;
import java.awt.Component;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerDateModel;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;


public class DateSpinner extends AbstractCellEditor implements TableCellEditor,
		TableCellRenderer {
	private JSpinner editSpinner, renderSpinner;
	Calendar cale ;
	SpinnerDateModel m;

	public DateSpinner() {
	cale = Calendar.getInstance();
	cale.clear();
	cale.setTimeInMillis(System.currentTimeMillis());
	cale.set(Calendar.HOUR_OF_DAY, 9);
	cale.set(Calendar.MINUTE, 0);
	cale.set(Calendar.SECOND, 0);
	m = new SpinnerDateModel(new Date(cale.getTimeInMillis()), null, null, Calendar.SECOND);
	editSpinner = new JSpinner(m);
	renderSpinner = new JSpinner(m);
	JSpinner.DateEditor editDe = new JSpinner.DateEditor(editSpinner, "HH:mm:ss");
	JSpinner.DateEditor renderDe = new JSpinner.DateEditor(editSpinner, "HH:mm:ss");
    editSpinner.setEditor(editDe);      
    editSpinner.setValue(editSpinner.getModel().getValue());
    renderSpinner.setEditor(renderDe);
    renderSpinner.setValue(editSpinner.getModel().getValue());
	editSpinner.setBorder(new LineBorder(Color.BLUE));
   }

	@Override
	public Object getCellEditorValue() {
		// TODO Auto-generated method stub
		return editSpinner.getValue();
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		// TODO Auto-generated method stub
		renderSpinner.setValue(renderSpinner.getModel().getValue());
		return renderSpinner;
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
	boolean isSelected, int row, int column) {
		// TODO Auto-generated method stub
		editSpinner.setValue(editSpinner.getModel().getValue());
		return editSpinner;
	}

}
